package com.util;

import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class DBSource{
public Connection getConn() {
		
		Connection conn=null;
		
		try {
			InputStream fis=this.getClass().getResourceAsStream("dbm.properties");
			
			Properties pro=new Properties();
			
			pro.load(fis);
			String driver=pro.getProperty("driver");
			String url=pro.getProperty("url");
			String username=pro.getProperty("username");
			String password=pro.getProperty("password");
			
			Class.forName(driver);
			conn=DriverManager.getConnection(url,username,password);
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		
		return conn;
	}
	
	public void closeConn(Connection conn) {
		
		try {
			if(conn !=null && !conn.isClosed()){
				
				conn.close();
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
